package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.system.ITripArea;
import com.gec.model.system.ITripComments;
import com.gec.model.vo.ITripAreaQueryVo;
import com.gec.model.vo.ITripCommentsVo;
import com.gec.system.common.Result;
import com.gec.system.service.ITripAreaService;
import com.gec.system.service.ITripCommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dafei
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/system/itrComments")
@Api(tags="评论管理")
@CrossOrigin
public class ITripCommentsController {
    @Autowired
    private ITripCommentsService iTripCommentsService;


//    @ApiOperation("获取全部")
//
//    @GetMapping("/findAll")
//    public Result findAll()
//    {
//        List<ITripComments> list = this.iTripCommentsService.list();
//        return Result.ok(list);
//    }




    @ApiOperation("根据id去移除一个角色")
    // 测试删除
    @DeleteMapping("/removeComments/{id}")
    public Result removeComments(@PathVariable Long id)
    {
        boolean b = this.iTripCommentsService.removeById(id);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }



    // 分页查询  通过空间id获取对应的所有评论信息 点进空间调用这个方法获取空间下的所有评论
    @GetMapping("/{page}/{limit}")
    public Result findCommentsByPageQuery(@PathVariable Long page,
                                      @PathVariable Long limit,
                                      Long spaceId)
    {
        //1.创建分页对象
        IPage<ITripComments> p1 = new Page<>(page,limit);
        //2.调用方法  通过空间id获取所有信息
        p1 =    this.iTripCommentsService.getBySpaceId(p1,spaceId);
        //3.返回
        return Result.ok(p1);
    }
    // 添加

//    @PostMapping("/addComments")
//    public Result addComments(@RequestBody ITripComments iTripComments)
//    {
//        boolean res = this.iTripCommentsService.save(iTripComments);
//        if (res)
//        {
//            return Result.ok();
//        }
//        else
//        {
//            return Result.fail();
//        }
//    }
    // 修改

    @GetMapping("/findCommentsById/{id}")
    public Result findCommentsById(@PathVariable Long id)
    {
        ITripComments iTripComments = this.iTripCommentsService.getById(id);
        return Result.ok(iTripComments);
    }



    // 实现修改
    @PostMapping("/updateComments")
    public Result updateComments(@RequestBody ITripComments iTripComments)
    {
        boolean b = this.iTripCommentsService.updateById(iTripComments);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 批量删除
    @DeleteMapping("/removeCommentsByIds")
    public Result removeCommentsByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.iTripCommentsService.removeByIds(ids);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
}

